/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package propriedadesLog;

import logs.Log;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Kdc
 */
public class PropriedadesLog {

    private Properties logEscolhido = new Properties();
    private String nomeLogEscolhido;
    private FileInputStream enderecoIn;
    private FileOutputStream enderecoOut;

    public PropriedadesLog() {
        try {
            enderecoIn = new FileInputStream("src/propriedadesLog/properties/logs.properties");

        } catch (FileNotFoundException ex) {
            Logger.getLogger(PropriedadesLog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void carregaLog() {
        try {
            logEscolhido.load(enderecoIn);

        } catch (IOException ex) {
            Logger.getLogger(PropriedadesLog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void salvarLog(int numeroLog) {
        try {
            enderecoOut = new FileOutputStream("src/propriedadesLog/properties/logs.properties");
            String caminhoLog = "";
            if (numeroLog == 0) {
                caminhoLog = "Logs.HtmlLog";
            } else if (numeroLog == 1) {
                caminhoLog = "Logs.MyTXTLog";
            }

            logEscolhido.clear();
            logEscolhido.put("0", caminhoLog);
            logEscolhido.store(enderecoOut, caminhoLog);

        } catch (IOException ex) {
            Logger.getLogger(PropriedadesLog.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public Log pegarLog() throws Exception {
        carregaLog();
        Log log = null;
        nomeLogEscolhido = logEscolhido.getProperty("0");
        Class classe = Class.forName(nomeLogEscolhido);
        Object object = classe.newInstance();
        log = (Log) object;
        return log;
    }
}
